﻿using System.Windows;

namespace KPM.Common.DragHelpers
{
    public static class MouseCapture
    {
        private static UIElement captured;

        public static bool Capture(UIElement element)
        {
            if (captured != null)
            {
                return false;
            }

            captured = element;
            element.CaptureMouse();
            return true;
        }

        public static bool IsCaptured()
        {
            return captured != null;
        }

        public static bool IsCaptured(UIElement element)
        {
            if (!IsCaptured())
            {
                return false;
            }

            return element == captured;
        }

        public static bool Release(UIElement element)
        {
            if (captured == null)
            {
                return false;
            }

            element.ReleaseMouseCapture();
            captured = null;
            return true;
        }
    }
}